package cn.k23.config.autoconfig;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

/**
 * @Description:
 * @Author: k23
 * @Date: 2022-05-10 9:48
 * @Version: 1.0
 */

/*引入一个第三方的组件 再配合 @Component注解 解决@ConfigurationProperties爆红问题
* @Component：标注Spring管理的Bean，
* 使用@Component注解在一个类上，表示将此类标记为Spring容器中的一个Bean。
* */
//@Component
@ConfigurationProperties(prefix = "by.token")
public class TokenProperties {
    final int DEFAULT_VALIDATE_TIME = 60; //过期时间 默认60分钟
    boolean enable; //是否开启token验证功能
    List<String> pathPatterns; //taken拦截的路径
    List<String> excludePathPatterns; //taken不拦截的路径
    String secret; //token生成的密钥
    int validateTime; //有效时间 单位分钟




    public boolean isEnable() {
        return enable;
    }

    public void setEnable(boolean enable) {
        this.enable = enable;
    }

    public List<String> getPathPatterns() {
        if (null == this.pathPatterns){
            this.pathPatterns = new ArrayList<>();
            this.pathPatterns.add("/**");//默认拦截所有请求

        }
        return pathPatterns;
    }

    public void setPathPatterns(List<String> pathPatterns) {
        this.pathPatterns = pathPatterns;
    }

    public List<String> getExcludePathPatterns() {
        if (null == this.excludePathPatterns){
            this.excludePathPatterns = new ArrayList<>();
        }
        return excludePathPatterns;
    }

    public void setExcludePathPatterns(List<String> excludePathPatterns) {
        this.excludePathPatterns = excludePathPatterns;
    }

    public String getSecret() {
        if (null == this.secret){
            this.secret= UUID.randomUUID().toString();//随机产生一个uuid字符串
        }
        return secret;
    }

    public void setSecret(String secret) {
        this.secret = secret;
    }

    public int getValidateTime() {
        if (this.validateTime == 0){
            this.validateTime = DEFAULT_VALIDATE_TIME;
        }
        return validateTime;
    }

    public void setValidateTime(int validateTime) {
        this.validateTime = validateTime;
    }
}
